<template>
  <div>
    <el-form
      label-width="240px"
    >
      <el-form-item label="appKey">
        <el-input v-model="companyConfigJiguangPush.appKey" />
      </el-form-item>
      <el-form-item label="masterSecret">
        <el-input v-model="companyConfigJiguangPush.masterSecret" />
      </el-form-item>
      <el-form-item :label="$t('save')">
        <el-button type="primary" @click="installOrUpdateCompanyConfigJiguangPush">{{ $t('confirm') }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { successNotice } from '@/util/common'
import {
  getCompanyConfigJiguangPush,
  installOrUpdateCompanyConfigJiguangPush
} from '@/api/common/commonCompanyConfigJiguangPushApi'

export default {
  name: 'JiguangPush',
  props: {
    companyId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      companyConfigJiguangPush: {
        appKey: '',
        masterSecret: '',
        companyId: this.companyId
      }
    }
  }, created() {
    this.getCompanyConfigJiguangPush()
  }, methods: {
    getCompanyConfigJiguangPush() {
      getCompanyConfigJiguangPush({
        companyId: this.companyId
      }).then(res => {
        const { data } = res
        if (data) {
          this.companyConfigJiguangPush = data
        }
      })
    },
    installOrUpdateCompanyConfigJiguangPush() {
      installOrUpdateCompanyConfigJiguangPush({
        ...this.companyConfigJiguangPush
      }).then(res => {
        const { code } = res
        if (code === '200') {
          successNotice(this)
          this.getCompanyConfigJiguangPush()
        }
      })
    }
  }
}
</script>

